#include <iostream>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <sys/wait.h>
using namespace std; 
void sig_child(int n ){
	int status; 
	cout << " I am in signal handler \n"; 
	wait(&status); 
	cout << " chidl handle over \n" ; 
}
int main(){
	cout << getpid() << endl;
	signal(SIGCHLD,sig_child); 
	if(fork() == 0){
		cout << " child " << endl;
		sleep(1); 
	}else{
		cout << getpid() << endl;
		cout <<  " parent " << endl;
		if(fork()  == 0){
			cout << " 2 child " << endl;
			sleep(3);
			return 0; 
		}
		cout << " 创建完第二个进程后的parent " << endl;
		int status; 
		//wait(&status);
		while(1);
	}
}
